import request from '@/utils/request'
import { CommonSearch } from '@/config/list'
import { StarTreeNode } from '@/model/common/tree/model'
import { RoleList, RoleBeanData } from '@/model/system/role/model'

export function loadRoleTree () {
  return request<StarTreeNode[]>({
    url: '/starRole/loadTree'
  })
}

export function loadRoleListByFid (data: CommonSearch) {
  return request<RoleList>({
    url: '/starRole/loadRoleListByFid',
    data: data,
    method: 'post'
  })
}

export function getMaxIndex (fid: string) {
  return request<number>({
    url: `/starRole/getMaxIndex?fid=${fid}`
  })
}

export function checkRoleType (formData: RoleBeanData) {
  return request({
    url: '/starRole/check',
    data: formData,
    method: 'post'
  })
}

export function saveRole (formData: RoleBeanData) {
  return request({
    url: '/starRole/save',
    data: formData,
    method: 'post'
  })
}

export function loadRoleById (id: string) {
  return request({
    url: `/starRole/loadRoleById?id=${id}`
  })
}

export function deleteRole (id: string) {
  return request({
    url: `/starRole/removeRole?id=${id}`
  })
}
